# -*- coding: utf-8 -*-
"""
Created on Wed May 15 20:15:34 2019

@author: yaoyu
"""

import pandas as pd
import numpy as np

data = [[      'Liuzi'  ,    'M' ,  21 ,  'Cantonese-style' ],
        [    'Huangqi'  ,    'F' ,  32 ,         'Su-style' ],
        [   'Yuanyuan'  ,    'F' ,  35 ,         'Su-style' ],
        [      'Duyue'  ,    'F' ,  14 ,  'Cantonese-style' ],
        [  'Zhangtian'  ,    'M' ,  33 ,  'Cantonese-style' ],
        ]

mooncakes_df = pd.DataFrame(data,columns=['name', 'gender',  'age', 'taste of mooncake'])
print(mooncakes_df)


def f(df):
     return df.age.count()
mooncakes_df.groupby('taste of mooncake').apply(f)

def foo(df):
    return df.sort_values('age')

def foo(df, column= 'age'):
    return df.sort_values(column)

print(mooncakes_df.groupby('taste of mooncake').apply(foo))




